<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>栈空间和堆空间：数据是如何存储的？</title>
  </head>
  <body>
    <script>
      function fun() {
        var a = "极客时间";
        var b = a;
        var c = { name: "极客时间" };
        var d = c;
      }
      fun();

      function foo() {
        var myName = "极客时间";
        var varFieldinClousre = "test";
        let test1 = 1;
        const test2 = 2;
        var innerBar = {
          setName: function (newName) {
            myName = newName;
          },
          getName: function () {
            console.log(test1);
            return myName;
          },
        };
        return innerBar;
      }
      var bar = foo();
      console.log(bar.getName());
      bar.setName("极客邦");
      console.log(bar.getName());

      let jack = {
        name: "jack.ma",
        age: 40,
        like: {
          dog: {
            color: "black",
            age: 3,
          },
          cat: {
            color: "white",
            age: 2,
          },
        },
      };
      function copy(src) {
        let dest = {};
        //实现拷贝代码，将src的值完整地拷贝给dest
        //在这里实现
        dest = src;
        return dest;
      }
      let jack2 = copy(jack);

      //比如修改jack2中的内容，不会影响到jack中的值
      jack2.like.dog.color = "green";
      console.log(jack.like.dog.color); //打印出来的应该是 "black"
    </script>
  </body>
</html>
